<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item
        ><a href="/">资源申请已通过列表</a></el-breadcrumb-item
      >
    </el-breadcrumb>

    <el-card>
      <!-- 搜索、添加、自定义列 -->
      <el-row :gutter="20">
        <el-col :span="12">
          <el-input placeholder="请输入设备名称" v-model="query.deviceName">
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getList"
            ></el-button>
          </el-input>
        </el-col>
        <!-- <el-col :span="3">
          <el-button type="primary" @click="showAddDialog">添加设备</el-button>
        </el-col> -->
        <el-col :span="3">
          <el-button type="success" @click="showSetColumn">自定义列</el-button>
        </el-col>
      </el-row>
      <!-- 内容列表 -->
      <el-table :data="list" border stripe>
        <el-table-column label="序号" type="index"></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '设备名称').show"
          label="设备名称"
          prop="deviceName"
          width="100"
        ></el-table-column>
        <!-- 审批操作 -->
        <el-table-column label="审批操作" width="80">
          <template slot-scope="scope">
            <!-- 审批 -->
            <el-tooltip effect="dark" content="重审" placement="top">
              <el-button type="warning" size="mini" @click="reset(scope.row)"
                >重审</el-button
              >
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '设备数量').show"
          label="设备数量"
          prop="count"
          width="100"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '设备号').show"
          label="设备号"
          prop="deviceNumber"
          width="100"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '设备编号').show"
          label="设备编号"
          prop="id"
          width="100"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '领用单位').show"
          label="领用单位"
          prop="useUnit"
          width="100"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '领用人编号').show"
          label="领用人编号"
          prop="userId"
          width="120"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '领用人').show"
          label="领用人"
          prop="userName"
          width="100"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '审批状态').show"
          label="审批状态"
          prop="approvalStatus"
          width="100"
          ><template slot-scope="scope">
            {{
              scope.row.approvalStatus == 0
                ? "审批中"
                : scope.row.approvalStatus == 1
                ? "通过"
                : scope.row.approvalStatus == 2
                ? "驳回"
                : "暂无"
            }}
          </template>
        </el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '购买日期').show"
          label="购买日期"
          prop="buyDate"
          width="100"
          ><template slot-scope="scope">
            {{ scope.row.createTime.substring(0, 10) }}
          </template></el-table-column
        >
        <el-table-column
          v-if="showColumns.find((i) => i.label == '分类号').show"
          label="分类号"
          prop="categoryNumber"
          width="80"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '型号').show"
          label="型号"
          prop="model"
          width="80"
        ></el-table-column>
        <!-- <el-table-column label="头像短链接" prop="portrait" width="100"></el-table-column> -->
        <el-table-column
          v-if="showColumns.find((i) => i.label == '现存放地址').show"
          label="现存放地址"
          prop="newAddress"
          width="100"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '原存放地址').show"
          label="原存放地址"
          prop="oldAddress"
          width="120"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '单价').show"
          label="单价"
          prop="price"
          width="100"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '报废日期').show"
          label="报废日期"
          prop="scrapDate"
          width="120"
          ><template slot-scope="scope">
            {{ scope.row.createTime.substring(0, 10) }}
          </template></el-table-column
        >
        <el-table-column
          v-if="showColumns.find((i) => i.label == '来源').show"
          label="来源"
          prop="source"
          width="120"
        >
          <template slot-scope="scope">
            {{
              scope.row.source == 0
                ? "购买"
                : scope.row.source == 1
                ? "历史导入"
                : scope.row.source == 2
                ? "盘盈"
                : "暂无"
            }}
          </template></el-table-column
        >
        <el-table-column
          v-if="showColumns.find((i) => i.label == '创建时间').show"
          label="创建时间"
          prop="createTime"
          width="150"
        >
          <template slot-scope="scope">
            {{ scope.row.createTime.substring(0, 10) }}
          </template>
        </el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '最后修改时间').show"
          label="最后修改时间"
          prop="modifyTime"
          width="150"
        >
          <template slot-scope="scope">
            {{ scope.row.modifyTime.substring(0, 10) }}
          </template>
        </el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '备注').show"
          label="备注"
          prop="remarks"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '规格').show"
          label="规格"
          prop="specifications"
          width="100"
        ></el-table-column>
        <el-table-column
          v-if="showColumns.find((i) => i.label == '状态').show"
          label="状态"
          prop="status"
          width="120"
        >
          <template slot-scope="scope">
            {{
              scope.row.roleType == 0
                ? "正常"
                : scope.row.roleType == 1
                ? "报废"
                : scope.row.roleType == 2
                ? "盘亏"
                : scope.row.roleType == 2
                ? "丢损"
                : "暂无"
            }}
          </template></el-table-column
        >

        <!-- 操作 -->
        <el-table-column label="操作" width="130">
          <template slot-scope="scope">
            <!-- 查看 -->
            <el-tooltip effect="dark" content="查看" placement="top">
              <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="showDetailDialog(scope.row)"
              ></el-button>
            </el-tooltip>
            <!-- 修改 -->
            <!-- <el-tooltip effect="dark" content="修改" placement="top">
              <el-button
                type="warning"
                icon="el-icon-edit"
                size="mini"
                @click="showEditDialog(scope.row)"
              ></el-button>
            </el-tooltip> -->
            <!-- 删除 -->
            <el-tooltip
              v-if="scope.row.account != 'admin'"
              effect="dark"
              content="删除"
              placement="top"
            >
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                @click="del(scope.row.id)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.pageNum"
        :page-sizes="[5, 10, 20, 30]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>

    <!-- 自定义列 -->
    <CustomColumn ref="columns" :showColumns="showColumns"></CustomColumn>

    <!-- 详情 -->
    <el-dialog
      title="用户详情"
      :visible.sync="showDetailVisible"
      width="70%"
      @close="hideDetailDialog"
      center
    >
      <el-form :model="detail" label-width="80px">
        <el-row :gutter="30">
          <el-col :span="8">
            <el-form-item label="审批状态:">
              <el-input v-model="detail.approvalStatus" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="购买日期:">
              <el-input v-model="detail.buyDate" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="分类号:">
              <el-select
                disabled
                v-model="detail.categoryNumber"
                placeholder="请选择"
                @change="handleAdd"
              >
                <el-option
                  v-for="item in options"
                  :key="item.id"
                  :label="item.value"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="8">
            <el-form-item label="设备名称:">
              <el-input v-model="detail.deviceName" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备号:">
              <el-input v-model="detail.deviceNumber" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="型号:">
              <el-input v-model="detail.model" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="8">
            <el-form-item label="现存放地址:">
              <el-input v-model="detail.newAddress" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="原存放地址:">
              <el-input v-model="detail.oldAddress" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报废日期:">
              <el-input v-model="detail.scrapDate" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="8">
            <el-form-item label="来源:">
              <el-input v-model="detail.source" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="规格:">
              <el-input v-model="detail.specifications" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="状态:">
              <el-input v-model="detail.status" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="领用单位:">
          <el-input v-model="detail.useUnit" disabled></el-input>
        </el-form-item>
        <el-form-item label="领用人编号:">
          <el-input v-model="detail.userId" disabled></el-input>
        </el-form-item>
        <el-form-item label="领用人:">
          <el-input v-model="detail.userName" disabled></el-input>
        </el-form-item>
        <el-form-item label="备注:">
          <el-input
            type="textarea"
            v-model="detail.remarks"
            disabled
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="hideDetailDialog">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 新增 -->
    <el-dialog
      title="新增设备"
      :visible.sync="showAddVisible"
      width="70%"
      @close="hideAddDialog"
      center
    >
      <el-form :model="addForm" ref="addFormRef" label-width="80px">
        <el-row :gutter="30">
          <el-col :span="8">
            <el-form-item
              label="设备数量:"
              prop="count"
              :rules="[
                { required: true, message: '数字不能为空', trigger: 'blur' },
                {
                  pattern: /^(0|[1-9][0-9]*)$/,
                  message: '请输入数字',
                  trigger: 'blur',
                },
              ]"
            >
              <el-input v-model="addForm.count"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="购买日期:">
              <el-date-picker
                v-model="addForm.buyDate"
                clearable
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="分类号:" prop="categoryNumber">
              <el-select
                v-model="addForm.categoryNumber"
                placeholder="请选择"
                @change="handleAdd"
              >
                <el-option
                  v-for="item in options"
                  :key="item.id"
                  :label="item.value"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="8">
            <el-form-item
              label="设备名称:"
              prop="deviceName"
              :rules="[
                {
                  required: true,
                  message: '设备名称不能为空',
                  trigger: 'blur',
                },
              ]"
            >
              <el-input v-model="addForm.deviceName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备号:" prop="deviceNumber">
              <el-input v-model="addForm.deviceNumber"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="型号:">
              <el-input v-model="addForm.model"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="8">
            <el-form-item label="领用单位:">
              <el-input v-model="addForm.useUnit"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="领用人编号:">
              <el-input v-model="addForm.userId"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报废日期:">
              <el-date-picker
                v-model="addForm.scrapDate"
                clearable
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="8">
            <el-form-item
              label="来源:"
              prop="source"
              :rules="[
                {
                  required: true,
                  message: '来源不能为空',
                  trigger: 'blur',
                },
              ]"
            >
              <el-select style="width: 100%" v-model="addForm.source">
                <el-option label="购买" :value="0"></el-option>
                <el-option label="历史导入" :value="1"></el-option>
                <el-option label="盘盈" :value="2"></el-option>
                <el-option label="未知" :value="null"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="规格:">
              <el-input v-model="addForm.specifications"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单价:">
              <el-input v-model="addForm.price"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="现存放地址:">
          <el-input v-model="addForm.newAddress"></el-input>
        </el-form-item>
        <el-form-item label="原存放地址:" prop="oldAddress">
          <el-input v-model="addForm.oldAddress"></el-input>
        </el-form-item>
        <el-form-item label="备注:">
          <el-input
            type="textarea"
            v-model="addForm.remarks"
            disabled
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="hideAddDialog">取 消</el-button>
        <el-button type="primary" @click="add">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 修改 -->
    <el-dialog
      title="修改设备"
      :visible.sync="showEditVisible"
      width="70%"
      @close="hideEditDialog"
      center
    >
      <el-form :model="editForm" ref="editFormRef" label-width="80px">
        <el-row :gutter="30">
          <el-col :span="8">
            <el-form-item
              label="设备数量:"
              prop="count"
              :rules="[
                { required: true, message: '数字不能为空', trigger: 'blur' },
                {
                  pattern: /^(0|[1-9][0-9]*)$/,
                  message: '请输入数字',
                  trigger: 'blur',
                },
              ]"
            >
              <el-input v-model="editForm.count"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="购买日期:">
              <el-date-picker
                v-model="editForm.buyDate"
                clearable
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="分类号:" prop="categoryNumber">
              <el-select
                v-model="editForm.categoryNumber"
                placeholder="请选择"
                @change="handleAdd"
              >
                <el-option
                  v-for="item in options"
                  :key="item.id"
                  :label="item.value"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="8">
            <el-form-item
              label="设备名称:"
              prop="deviceName"
              :rules="[
                {
                  required: true,
                  message: '设备名称不能为空',
                  trigger: 'blur',
                },
              ]"
            >
              <el-input v-model="editForm.deviceName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="设备号:" prop="deviceNumber">
              <el-input v-model="editForm.deviceNumber"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="型号:">
              <el-input v-model="editForm.model"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="8">
            <el-form-item label="领用单位:">
              <el-input v-model="editForm.useUnit"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="领用人编号:">
              <el-input v-model="editForm.userId"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报废日期:">
              <el-date-picker
                v-model="editForm.scrapDate"
                clearable
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="8">
            <el-form-item
              label="来源:"
              prop="source"
              :rules="[
                {
                  required: true,
                  message: '来源不能为空',
                  trigger: 'blur',
                },
              ]"
            >
              <el-select style="width: 100%" v-model="addForm.source">
                <el-option label="购买" :value="0"></el-option>
                <el-option label="历史导入" :value="1"></el-option>
                <el-option label="盘盈" :value="2"></el-option>
                <el-option label="未知" :value="null"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="规格:">
              <el-input v-model="editForm.specifications"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单价:">
              <el-input v-model="editForm.price"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="现存放地址:">
          <el-input v-model="editForm.newAddress"></el-input>
        </el-form-item>
        <el-form-item label="原存放地址:" prop="oldAddress">
          <el-input v-model="editForm.oldAddress"></el-input>
        </el-form-item>
        <el-form-item label="备注:">
          <el-input
            type="textarea"
            v-model="editForm.remarks"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="hideEditDialog">取 消</el-button>
        <el-button type="primary" @click="edit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import md5 from "js-md5";
import CustomColumn from "../components/CustomColumn.vue";
export default {
  components: { CustomColumn },
  data() {
    return {
      //领用人信息
      info: {},
      //分类编号选择项
      options: [],
      // 查询条件
      query: {
        approvalStatus: 4,
        name: "",
        categoryNumber: "",
        pageNum: 1,
        pageSize: 10,
      },
      // 内容列表
      list: [],
      // 内容总条数
      total: 0,
      query1: {
        name: "",
        categoryNumber: "",
        pageNum: 1,
        pageSize: "",
      },
      // 初始化显示字段
      showColumns: [
        { label: "审批状态", show: true },
        { label: "购买日期", show: false },
        { label: "分类号", show: true },
        { label: "设备数量", show: true },
        { label: "创建时间", show: false },
        { label: "设备名称", show: true },
        { label: "设备号", show: true },
        { label: "设备编号", show: true },
        { label: "型号", show: false },
        { label: "最后修改时间", show: false },
        { label: "现存放地址", show: false },
        { label: "原存放地址", show: false },
        { label: "单价", show: false },
        { label: "备注", show: true },
        { label: "报废日期", show: false },
        { label: "来源", show: true },
        { label: "规格", show: true },
        { label: "状态", show: true },
        { label: "领用单位", show: true },
        { label: "领用人编号", show: true },
        { label: "领用人", show: true },
      ],
      // 是否显示详情
      showDetailVisible: false,
      // 数据详情
      detail: {},
      // 是否显示新增
      showAddVisible: false,
      // 新增数据
      addForm: {},
      // 是否显示修改
      showEditVisible: false,

      // 是否审批
      approvalForm: false,
      // 修改数据
      editForm: {},
    };
  },
  created() {
    this.getList();
    this.getList1();
    this.getList2();
  },
  methods: {
    // 显示自定义列
    showSetColumn() {
      this.$refs.columns.dialogVisible = true;
    },
    // 获取内容列表
    getList() {
      this.$http.post("/v1/api/devices/page", this.query).then((res) => {
        if (res.data.code == 0) {
          this.list = res.data.data.list;
          this.total = res.data.data.total;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    //获取资源分类编号
    getList1() {
      this.$http.post("/v1/api/categories/page", this.query1).then((res) => {
        if (res.data.code == 0) {
          // this.list = res.data.data.list;
          // this.total = res.data.data.total;
          // console.log(res.data.data.list);
          var gotList = res.data.data.list;
          gotList.forEach((v) => {
            this.options.push({
              value: v.name,
              id: v.id,
            });
          });
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    //获取领用人列表
    getList2() {
      var userInfo = JSON.parse(localStorage.getItem("userInfo"));
      console.log(userInfo.account);
      this.info = userInfo;
    },
    //监听分类编号改变
    handleAdd() {
      this.query.categoryNumber = this.name;
      console.log(this.name);
    },
    handleChange() {
      this.query.categoryNumber = this.name;
      this.getList();
      console.log(this.name);
    },
    // 监听 pageSize 改变的事件
    handleSizeChange(pageSize) {
      this.query.pageSize = pageSize;
      this.getList();
    },
    // 监听 page 改变的事件
    handleCurrentChange(page) {
      this.query.pageNum = page;
      this.getList();
    },
    // 显示详情
    showDetailDialog(row) {
      this.detail = row;
      this.showDetailVisible = true;
    },
    // 隐藏详情
    hideDetailDialog() {
      this.detail = {};
      this.showDetailVisible = false;
    },
    // 显示新增
    showAddDialog() {
      this.addForm = {
        buyDate: "",
        categoryNumber: "",
        count: "",
        deviceName: "",
        deviceNumber: "",
        model: "",
        newAddress: "",
        oldAddress: "",
        price: "",
        remarks: "",
        scrapDate: "",
        source: "",
        specifications: "",
        useUnit: "",
        userId: "",
      };
      this.showAddVisible = true;
    },
    // 隐藏新增
    hideAddDialog() {
      this.showAddVisible = false;
    },
    // 新增
    add() {
      this.$refs.addFormRef.validate((valid) => {
        if (valid) {
          // this.addForm.password = md5(this.addForm.password);
          this.$http.post("/v1/api/devices", this.addForm).then((res) => {
            if (res.data.code == 0) {
              this.getList();
              this.$message.success("新增成功");
              this.showAddVisible = false;
            } else {
              this.$message.error(res.data.msg);
            }
          });
        } else {
          this.$message.error("请填写必填项");
          return false;
        }
      });
    },
    // 删除
    del(id) {
      this.$confirm("此操作将永久删除该用户, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http.delete("/v1/api/devices/" + id).then((res) => {
            if (res.data.code == 0) {
              this.getList();
              this.$message.success("删除成功");
            }
          });
        })
        .catch(() => {
          this.$message.info("已取消");
        });
    },
    // 显示修改
    showEditDialog(row) {
      this.editForm = row;
      this.showEditVisible = true;
    },
    // 隐藏修改
    hideEditDialog() {
      this.showEditVisible = false;
    },
    reset(row) {
      this.approvalForm = row;
      this.approvalForm.approvalStatus = 1;
      console.log(this.approvalForm);
      this.showpass = true;
      this.$http.put("/v1/api/devices", this.approvalForm).then((res) => {
        if (res.data.code == 0) {
          this.getList();
          this.$message.success("已递交重审");
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    pass(row) {
      this.approvalForm = row;
      this.approvalForm.approvalStatus = 1;
      console.log(this.approvalForm);
      this.showpass = true;
      this.$http.put("/v1/api/devices", this.approvalForm).then((res) => {
        if (res.data.code == 0) {
          this.getList();
          this.$message.success("已通过申请");
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    reject(row) {
      this.approvalForm = row;
      this.approvalForm.approvalStatus = 2;
      console.log(this.approvalForm);
      this.showpass = true;
      this.$http.put("/v1/api/devices", this.approvalForm).then((res) => {
        if (res.data.code == 0) {
          this.getList();
          this.$message.success("已驳回申请");
        } else {
          this.$message.error(res.data.msg);
        }
      });
    },
    // 修改
    edit() {
      this.$refs.editFormRef.validate((valid) => {
        if (valid) {
          this.$http.put("/v1/api/devices", this.editForm).then((res) => {
            if (res.data.code == 0) {
              this.getList();
              this.$message.success("修改成功");
              this.showEditVisible = false;
              this.showpass = false;
            } else {
              this.$message.error(res.data.msg);
            }
          });
        } else {
          this.$message.error("请填写必填项");
          return false;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.el-breadcrumb {
  margin-bottom: 15px;
  font-size: 12px;
}
</style>
